package com.uzai.console.common;

import java.io.Serializable;

/**
 * @Auther: jianghan
 * @Date: 2021/9/8 14:37
 * @Description:
 */
public class UzaiRespVo<T> implements Serializable {
    private static final long serialVersionUID = -2645790353127933049L;
    private int code;
    private String msg;
    private long time;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> UzaiRespVo<T> success(T data) {
        UzaiRespVo<T> res = new UzaiRespVo<>();
        res.setCode(200);
        res.setData(data);
        res.setMsg("success");
        res.setTime(System.currentTimeMillis());
        return res;
    }

    public static <T> UzaiRespVo<T> fail() {
        UzaiRespVo<T> res = new UzaiRespVo<>();
        res.setCode(500);
        res.setMsg("error");
        res.setTime(System.currentTimeMillis());
        return res;
    }

    public static <T> UzaiRespVo<T> fail(String errMsg) {
        UzaiRespVo<T> res = new UzaiRespVo<>();
        res.setCode(500);
        res.setMsg(errMsg);
        res.setTime(System.currentTimeMillis());
        return res;
    }
}
